﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MobiMenu.Restaurant.Data;
using System.Data.SqlClient;
using System.Configuration;
using MobiMenu.Restaurant;
using System.Diagnostics;
using System.IO;

public partial class test_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        using (SqlConnection conn = new SqlConnection(
            ConfigurationManager.ConnectionStrings["MobiMenuConnectionString"].ConnectionString))
        {
            DBManager db = new DBManager(conn);
            TextWriter tw = new StringWriter();
            db.Log = tw;

            IQueryable<Order> query = from order in db.Orders
                                      select order;

            foreach (Order order in query)
            {
                Output(order.Id.ToString() + ", " + order.TableId.ToString());
            }


            // Create the new Customer object.
            Order newOrder = new Order();
            newOrder.TableId = "5";
            newOrder.WaiterId = "218";
            newOrder.OrderedTime = DateTime.Now;

            // Add the customer to the Customers table.
            db.Orders.InsertOnSubmit(newOrder);
            //db.SubmitChanges();
            Output("After inserted order:");

            IQueryable<Order> query1 = from order in db.Orders
                                      select order;
            foreach (Order order in query)
            {
                Output(order.Id.ToString() + order.TableId.ToString());
            }

            TextReader stringReader =
            new StringReader(tw.ToString());
            Output(stringReader.ReadToEnd());
        }
    }


    private void Output(string s)
    {
        this.TextBox1.Text += s + "\r\n";
    }
}